/**
 * 详情对话框
 */
var OrderInfoDlg = {
    data: {
        orderNo: "",
        ownerUserId: "",
        ownerUser: "",
        payAmount: "",
        amount: "",
        costRate: "",
        payRate: "",
        orderStatus: "",
        createTime: "",
        updateTime: "",
        delFlag: "",
        approveUserId: "",
        approveUser: "",
        remark: ""
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/order/detail?orderId=" + Feng.getUrlParam("orderId"));
    var result = ajax.start();
    form.val('orderForm', result.data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/order/approve-success", function (data) {
                Feng.success("审核成功!");
                var pageSource =  $("#pageSouce").val();
                if (pageSource != null && pageSource != '' && pageSource == 'batch') {
                    window.location.href = Feng.ctxPath + '/batchOrder/edit?batchId=' + $("#batchId").val();
                } else {
                    window.location.href = Feng.ctxPath + '/order';
                }
            }, function (data) {
                Feng.error("通过失败!" + data.responseJSON.message + "!");
            });
            ajax.set(data.field);
            ajax.start();
        };
        Feng.confirm("是否通过?", operation);
        return false;
    });

    //表单提交事件
    form.on('submit(btnFail)', function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/order/approve-fail", function (data) {
                Feng.success("审核成功!");
                var pageSource =  $("#pageSouce").val();
                if (pageSource != null && pageSource != '' && pageSource == 'batch') {
                    window.location.href = Feng.ctxPath + '/batchOrder/edit?batchId=' + $("#batchId").val();
                } else {
                    window.location.href = Feng.ctxPath + '/order';
                }
            }, function (data) {
                Feng.error("拒绝失败!" + data.responseJSON.message + "!");
            });
            ajax.set(data.field);
            ajax.start();
        };
        Feng.confirm("是否拒绝?", operation);
        return false;
    });

    //计算结果
    $("#payRate,#itemQuota").on("change", function(){
        var payRate = $("#payRate").val();
        var itemQuota = $("#itemQuota").val();
        payRate = payRate != null?payRate:0;
        itemQuota = itemQuota != null?itemQuota:0;
        $("#payAmountLabel").text(payRate * itemQuota);
        $("#payAmount").val(payRate * itemQuota);

    });


    //返回按钮
    $("#backupPage").click(function () {
        var pageSource =  $("#pageSouce").val();
        if (pageSource != null && pageSource != '' && pageSource == 'batch') {
            window.location.href = Feng.ctxPath + '/batchOrder/edit?batchId=' + $("#batchId").val();
        } else {
            window.location.href = Feng.ctxPath + '/order';
        }
    });

});
